package com.ssy.invoicing.customer.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.ssy.invoicing.customer.bean.CustomerBean;
import com.ssy.invoicing.dao.support.BaseSqlDao;

/**
 * Comment of CustomerDao
 * @author suoyao.shen
 */
@Repository(value="customerDao")
public class CustomerDao extends BaseSqlDao {

    /**
     * 查询客户信息列表,分页
     * @author suoyao.shen
     * @param params
     * @param page
     * @return
     * @throws SQLException
     */
    public SplitPageResult queryCustomerList(Map<String, Object> params, int page)
            throws SQLException {
        return queryListByPagination("customer.queryCustomerList", "customer.queryCustomerCount",
                params, page);
    }
    
    /**
     * 查询客户详情
     * @author suoyao.shen
     * @param id
     * @return
     */
    public CustomerBean getCustomer(Integer id) {
        return (CustomerBean) queryForObject("customer.getCustomer", id);
    }
    
    /**
     * 删除客户信息
     * @author suoyao.shen
     * @param id
     */
    public void removeCustomer(Integer id) {
        delete("customer.removeCustomer", id);
    }
    
    /**
     * 保存客户信息
     * @param customer
     */
    public void saveCustomer(CustomerBean customer) {
        update("customer.insertCustomer", customer);
    }
    
    /**
     * 更新客户信息
     * @param customer
     */
    public void updateCustomer(CustomerBean customer) {
        update("customer.updateCustomer", customer);
    }
    
    /**
     * 根据类型查询客户信息
     * @param type
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<CustomerBean> queryCustomerByType(Integer type) {
        return (List<CustomerBean>) queryForList("customer.queryCustomerByType", type);
    }
    
}
